package com.saifan.wyy_ov.ui.onlishop;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.saifan.wyy_ov.R;
import com.saifan.wyy_ov.data.bean.MyOrderBean;
import com.saifan.wyy_ov.data.bean.MyOrderBean.OrderDetail;
import com.saifan.wyy_ov.utils.ImgUtil;
import com.saifan.wyy_ov.utils.PriceUtils;

import java.util.List;

public class AdapterOrderdetail extends BaseAdapter {
    Context context;
    List<OrderDetail> orderDetails;
    MyOrderBean myOrderBean;

    public AdapterOrderdetail(Context context, List<OrderDetail> orderDetails, MyOrderBean myOrderBean) {
        this.context = context;
        this.myOrderBean = myOrderBean;
        this.orderDetails = orderDetails;
    }

    @Override
    public int getCount() {
        return orderDetails.size();
    }

    @Override
    public Object getItem(int position) {
        return orderDetails.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        OrderDetail orderdetail = orderDetails.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.order_item, null);
            viewHolder.iv_ispay = (ImageView) convertView.findViewById(R.id.iv_ispay);
            viewHolder.iv_goods_image = (ImageView) convertView.findViewById(R.id.iv_goods_image);
            viewHolder.tv_goods_name = (TextView) convertView.findViewById(R.id.tv_goods_name);
            viewHolder.tv_count = (TextView) convertView.findViewById(R.id.tv_count);
            viewHolder.tv_total = (TextView) convertView.findViewById(R.id.tv_total);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (myOrderBean.getPaymentWay() == 1) {
            viewHolder.iv_ispay.setBackgroundResource(R.drawable.onlinepayment);
        } else if (myOrderBean.getPaymentWay() == 2) {
            viewHolder.iv_ispay.setBackgroundResource(R.drawable.payondelivery);
        } else if (myOrderBean.getPaymentWay() == 0){
            viewHolder.iv_ispay.setBackgroundResource(R.drawable.onlinepayment);
        }
        ImgUtil.DisPlayImg(orderdetail.getCoverPhoto(), viewHolder.iv_goods_image, context);
        viewHolder.tv_goods_name.setText(orderdetail.getGoodsName() + "");
        viewHolder.tv_count.setText(orderdetail.getCount() + "");
        viewHolder.tv_total.setText(PriceUtils.getPrice(orderdetail.getPrice()) + "元");
        return convertView;

    }

    static class ViewHolder {
        ImageView iv_ispay;
        ImageView iv_goods_image;
        TextView tv_goods_name;
        TextView tv_count;
        TextView tv_total;
    }
}
